<template>
  <div class="content">
    <page-web v-if="isPC" :news="news" :products="products"></page-web>
    <page-app v-else :news="news" :products="products"></page-app>
  </div>
</template>

<script>
import { mapState } from 'vuex'
import Panles from '@/container/index/importComponents'
import * as api from '@/const/api'

export default {
  title: '首页',
  name: 'Home',
  components: {
    ...Panles,
  },
  data() {
    return {
      news: [],
      products: []
    }
  },
  computed: {
    ...mapState(['isPC']),
  },
  created() {},
  mounted() {
    this.goNewsPage()
    this.goProductPage()
  },
  methods: {
    async goNewsPage() {
      try {
        this.loading = true
        const { code, msg, data } = await this.$axios.$post(api.solutionPage, {
          topShow: 1,
          pageNo: 1,
          pageSize: 3,
          solutionClassificationType: 3,
        })

        if (+code !== 200) {
          throw new Error(msg || this.$t('common.form.error'))
        }
        this.news = data.list || []
      } catch (err) {
        this.$message.error(err.message)
      } finally {
        this.loading = false
      }
    },
    async goProductPage() {
      try {
        this.loading = true
        const { code, msg, data } = await this.$axios.$post(api.solutionPage, {
          topShow: 1,
          pageNo: 1,
          pageSize: 6,
          solutionClassificationType: 2,
        })

        if (+code !== 200) {
          throw new Error(msg || this.$t('common.form.error'))
        }
        this.products = data.list || []
      } catch (err) {
        this.$message.error(err.message)
      } finally {
        this.loading = false
      }
    },
  },
}
</script>

<style lang="less" scoped></style>
